import Vue from 'vue'
import Vuex from 'vuex'
import { setToken, getToken } from '@/utils/storage'
Vue.use(Vuex)

const TOKENKEY = 'heimatoutiao'
export default new Vuex.Store({
  state: {
    user: getToken(TOKENKEY)
  },
  getters: {
  },
  mutations: {
    setUser (state, payload) {
      state.user = payload
      // 为了防止刷新丢失，我们需要把数据备份到本地存储
      setToken(TOKENKEY, state.user)
    }
  },
  actions: {
  },
  modules: {
  }
})
